﻿package game.objects {
	
	import flash.display.DisplayObject;
	import flash.display.MovieClip;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.events.FocusEvent;
	import flash.events.KeyboardEvent;
	import flash.geom.Rectangle;
	import flash.globalization.Collator;
	import flash.ui.Keyboard;
	import game.events.GameEvent;
	import game.value.GameValues;
	
	public class Flower extends MovieClip {
		protected var locationType:int = 0;
		private const starX:int = 100;
		private const starY:int = 530;
		
		private var game:main;
		public var removeTag:Boolean = false;//是否被碰撞到
		private var movieTag:int;
		//public var collisionRec:MovieClip = new MovieClip();
		//public var collisionRec:game.objects.CollisionRec;
		public var collisionRec:game.objects.Rec = new game.objects.Rec();
		//public var cRec:game.objects.CollisionRec;
		
		public function Flower(mygame:main) {
			stop();
			game = mygame;
			this.x = 255;
			this.y = 290;

			game.stage.addChild(collisionRec);
			
			this.addEventListener(Event.ENTER_FRAME, enterFramHandle);
			game.stage.addEventListener(KeyboardEvent.KEY_DOWN, keyboardHandler);
			
			game.stage.addChild(this);
		}
		
		public function enterFramHandle(e:Event):void {

			//trace("collistion move X:" + (this.x + 345));
			//trace("collistion move X:"+ (this.x + 345));
			//collisionRec.x -= 1;
		}
		
		public function keyboardHandler(e:KeyboardEvent):void {
			trace("keycode: " + e.keyCode);
			trace("原來位置："+ collisionRec.x +" Y:"+collisionRec.y);
			switch (e.keyCode) 
			{
				case 90:
					trace("z");
					this.gotoAndPlay("first");
					this.collisionRec.setLoction(this.x + 345 - 134);
					//this.collisionRec.y = this.x + 345 - 134; 
					//collisionRec.gotoAndPlay("first");
				break;
			case 88:
					trace("x");
					this.gotoAndPlay("second");
					this.collisionRec.setLoction(this.x + 345 - 334);
					//this.collisionRec.y = this.x + 345 - 334; 
					//collisionRec.gotoAndPlay("second");
				break;
			case 67:
					trace("c");
					this.gotoAndPlay("third");
					this.collisionRec.setLoction(this.x + 345 - 524);
					//this.collisionRec.y = this.x + 345 - 524; 
					
					//collisionRec.gotoAndPlay("third");
				break;
				default:
			}
		}
		
		public function remove():void {
			game.stage.removeEventListener(KeyboardEvent.KEY_DOWN, keyboardHandler);
			parent.removeChild(this);
		}
	}
	
}
